﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExtensionsExcercise
{
    class Program
    {
        static void Main(string[] args)
        {
            ToTitleCaseTest();
            return;

            Task6NumbersDivisibleBy3And7Linq();
            return;

            Task6NumbersDivisibleBy3And7();
            return;

            Task5OrderByThenByLinq();
            return;

            Task5OrderByThenBy();
            return;

            Task4FirstAndLastNameWithAge();
            return;

            

            StringBuilder b = new StringBuilder("abcdefghi");

            Console.WriteLine(b.Substring(3, 4));

            List<int> l = new List<int>() { 12, 21};
            int sum = l.Sum();

            Console.WriteLine(sum);

            Student[] students = new Student[] 
            { 
                new Student("A", "A"),
                new Student("A", "B"),
                new Student("B", "A"),
                new Student("A", "C"),
                new Student("C", "B"),
            };

            foreach (var student in students.WhereFirstNameIsBeforeLastName())
            {
                Console.WriteLine(student);
            }

            Console.WriteLine(students.Sum());

            TestGetFirstNameAndLastName();
        }

        public static void TestGetFirstNameAndLastName()
        {
            Student[] students = new Student[] 
            { 
                new Student("A", "A", 20),
                new Student("A", "B", 11),
                new Student("B", "A", 34),
                new Student("A", "C", 21),
                new Student("C", "B", 22),
            };

            int minAge = 12;
            int maxAge = 24;

            var trimmedStudents = from student in students
                         where student.Age >= minAge && student.Age <= maxAge
                         select new { student.FirstName, student.LastName };

            foreach (var s in trimmedStudents)
            {
                Console.WriteLine("{0} {1}", s.FirstName, s.LastName);
            }
            
        }

        static void Task4FirstAndLastNameWithAge()
        { 
            Student[] students = new Student[] 
            { 
                new Student("A", "A", 14),
                new Student("A", "B", 18),
                new Student("B", "A", 29),
                new Student("A", "C", 21),
                new Student("C", "B", 21),
            };

            var firstAndLastNameStudents = from s in students
                      where s.Age >= 18 && s.Age <= 24
                      select new { FirstName = s.FirstName, LastName = s.LastName };

            foreach (var item in firstAndLastNameStudents)
            {
                Console.WriteLine("{0} {1}", item.FirstName, item.LastName);
            }
                      
        }

        static void Task5OrderByThenBy()
        {
            Student[] students = new Student[] 
            { 
                new Student("A", "A", 14),
                new Student("A", "B", 18),
                new Student("B", "A", 29),
                new Student("A", "C", 21),
                new Student("C", "B", 21),
            };

            var orderedDesc = students.OrderByDescending(s => s.FirstName).ThenByDescending(s => s.LastName);

            foreach (var s in orderedDesc)
            {
                Console.WriteLine(s);
            }
        }

        static void Task5OrderByThenByLinq()
        {
            Student[] students = new Student[] 
            { 
                new Student("A", "A", 14),
                new Student("A", "B", 18),
                new Student("B", "A", 29),
                new Student("A", "C", 21),
                new Student("C", "B", 21),
            };

            var orderedDesc = from s in students
                              orderby s.FirstName descending
                              orderby s.LastName descending
                              select s;
                                 

            foreach (var s in orderedDesc)
            {
                Console.WriteLine(s);
            }
        }

        static void Task6NumbersDivisibleBy3And7()
        {
            int[] ints = { 1, 14, 1, 12, 5, 36, 346345, 46, 23, 14632, 214, 5, 1 };

            var divisibleBy3And7 = ints.Where(i => i % 3 == 0 || i % 7 == 0);

            foreach (var i in divisibleBy3And7)
            {
                Console.WriteLine(i);
            }
        }

        static void Task6NumbersDivisibleBy3And7Linq()
        {
            int[] ints = { 1, 14, 1, 12, 5, 36, 346345, 46, 23, 14632, 214, 5, 1 };

            var divisibleBy3And7 = from i in ints
                                   where i % 3 == 0 || i % 7 == 0
                                   select i;

            foreach (var i in divisibleBy3And7)
            {
                Console.WriteLine(i);
            }
        }

        static void ToTitleCaseTest()
        {
            string text = "ala bala nica,edno .dve i !polovina";
            Console.WriteLine(text.ToTitleCase());
        }

    }
}
